<%
  topologies = %w( standalone replica-set sharded-cluster )

  # latest_ruby = the most recently released, stable version of Ruby
  #    (make sure this version is being built by 10gen/mongo-ruby-toolchain)
  latest_ruby = "ruby-3.3".inspect # so it gets quoted as a string

  # these are used for testing against a few recent ruby versions
  recent_rubies = %w( ruby-3.3 ruby-3.2 jruby-9.4 )

  recent_mri_rubies = %w( ruby-3.3 ruby-3.2 )

  # this is a list of the most recent 3.x and 2.x MRI ruby versions
  sample_mri_rubies = %w( ruby-3.3 ruby-2.7 )

  # as above, but including the most recent JRuby release
  sample_rubies = sample_mri_rubies + %w( jruby-9.4 )

  # older Ruby versions provided by 10gen/mongo-ruby-toolchain
  older_rubies = %w( ruby-3.0 ruby-2.7  )

  # all supported JRuby versions provided by 10gen/mongo-ruby-toolchain
  jrubies = %w( jruby-9.4 jruby-9.3 )

  supported_mri_rubies_3 = %w( ruby-3.3 ruby-3.2 ruby-3.1 ruby-3.0 )

  supported_mri_rubies_3_ubuntu = %w( ruby-3.3 ruby-3.2 ruby-3.1 )

  supported_mri_ruby_2 = "ruby-2.7".inspect

  supported_rubies = supported_mri_rubies_3 +
                     %w( ruby-2.7 ) +
                     jrubies

  # The latest stable version of MongoDB
  latest_stable_mdb = "8.0".inspect # so it gets quoted as a string


  recent_mdb = %w( 8.0 7.0 )
%>

buildvariants:
  - matrix_name: DriverBench
    matrix_spec:
      ruby: <%= latest_ruby %>
      mongodb-version: <%= latest_stable_mdb %>
      topology: standalone
      os: ubuntu2204
    display_name: DriverBench
    tasks:
      - name: "driver-bench"

  - matrix_name: "auth/ssl"
    matrix_spec:
      auth-and-ssl: ["auth-and-ssl", "noauth-and-nossl"]
      ruby: <%= latest_ruby %>
      mongodb-version: <%= recent_mdb %>
      topology: <%= topologies %>
      os: ubuntu2204
    display_name: ${auth-and-ssl} ${ruby} db-${mongodb-version} ${topology}
    tasks:
      - name: "test-mlaunch"

  - matrix_name: "mongo-recent"
    matrix_spec:
      ruby: <%= recent_rubies %>
      mongodb-version: <%= recent_mdb %>
      topology: <%= topologies %>
      os: ubuntu2204
    display_name: "${mongodb-version} ${os} ${topology} ${auth-and-ssl} ${ruby}"
    tasks:
      - name: "run-main-test-suite"

  - matrix_name: "mongo-8-arm"
    matrix_spec:
      ruby: <%= latest_ruby %>
      mongodb-version: [ '8.0' ]
      topology: <%= topologies %>
      os: ubuntu2404-arm
    display_name: "${mongodb-version} ${os} ${topology} ${auth-and-ssl} ${ruby}"
    tasks:
      - name: "run-main-test-suite"

  - matrix_name: "mongo-5.x"
    matrix_spec:
      ruby: <%= recent_mri_rubies %>
      mongodb-version: ['5.0']
      topology: <%= topologies %>
      os: ubuntu2004
    display_name: "${mongodb-version} ${topology} ${auth-and-ssl} ${ruby}"
    tasks:
      - name: "run-main-test-suite"

  - matrix_name: "mongo-4.x"
    matrix_spec:
      ruby: <%= older_rubies %>
      mongodb-version: ['4.4', '4.2']
      topology: <%= topologies %>
      os: ubuntu1804
    display_name: "${mongodb-version} ${topology} ${auth-and-ssl} ${ruby}"
    tasks:
      - name: "run-main-test-suite"

  - matrix_name: "single-lb"
    matrix_spec:
      ruby: <%= latest_ruby %>
      mongodb-version: <%= latest_stable_mdb %>
      topology: load-balanced
      single-mongos: single-mongos
      os: ubuntu2204
    display_name: "${mongodb-version} ${topology} single-lb ${auth-and-ssl} ${ruby}"
    tasks:
      - name: "test-mlaunch"

  - matrix_name: "mongo-api-version"
    matrix_spec:
      ruby: <%= latest_ruby %>
      mongodb-version: '7.0'
      topology: standalone
      api-version-required: yes
      os: ubuntu2204
    display_name: "${mongodb-version} api-version-required ${topology} ${auth-and-ssl} ${ruby}"
    tasks:
      - name: "test-mlaunch"

  - matrix_name: "single-mongos"
    matrix_spec:
      ruby: <%= latest_ruby %>
      mongodb-version: <%= latest_stable_mdb %>
      topology: "sharded-cluster"
      single-mongos: single-mongos
      os: ubuntu2204
    display_name: "${mongodb-version} ${topology} single-mongos ${auth-and-ssl} ${ruby}"
    tasks:
      - name: "test-mlaunch"

  - matrix_name: CSOT
    matrix_spec:
      ruby: <%= latest_ruby %>
      mongodb-version: <%= latest_stable_mdb %>
      topology: replica-set-single-node
      os: ubuntu2204
    display_name: "CSOT - ${mongodb-version}"
    tasks:
      - name: test-csot

  - matrix_name: "no-retry-reads"
    matrix_spec:
      retry-reads: no-retry-reads
      ruby: <%= latest_ruby %>
      mongodb-version: <%= latest_stable_mdb %>
      topology: <%= topologies %>
      os: ubuntu2204
    display_name: "${mongodb-version} ${topology} ${retry-reads} ${ruby}"
    tasks:
      - name: "test-mlaunch"

  - matrix_name: "no-retry-writes"
    matrix_spec:
      retry-writes: no-retry-writes
      ruby: <%= latest_ruby %>
      mongodb-version: <%= latest_stable_mdb %>
      topology: [replica-set, sharded-cluster]
      os: ubuntu2204
    display_name: "${mongodb-version} ${topology} ${retry-writes} ${ruby}"
    tasks:
      - name: "test-mlaunch"

  - matrix_name: "lint"
    matrix_spec:
      lint: on
      ruby: <%= latest_ruby %>
      mongodb-version: <%= latest_stable_mdb %>
      topology: <%= topologies %>
      os: ubuntu2204
    display_name: "${mongodb-version} ${topology} ${lint} ${ruby}"
    tasks:
      - name: "test-mlaunch"

  - matrix_name: "fork"
    matrix_spec:
      fork: on
      ruby: <%= latest_ruby %>
      mongodb-version: <%= latest_stable_mdb %>
      topology: <%= topologies %>
      os: ubuntu2204
    display_name: "${mongodb-version} ${topology} fork ${ruby}"
    tasks:
      - name: "test-mlaunch"

  - matrix_name: "solo"
    matrix_spec:
      solo: on
      ruby: <%= supported_mri_rubies_3_ubuntu %>
      mongodb-version: <%= latest_stable_mdb %>
      topology: <%= topologies %>
      os: ubuntu2204
    display_name: "${mongodb-version} ${topology} solo ${ruby}"
    tasks:
      - name: "test-mlaunch"

  - matrix_name: "stress older"
    matrix_spec:
      stress: on
      ruby: <%= supported_mri_ruby_2 %>
      mongodb-version: ['4.4', '4.2']
      topology: replica-set
      os: ubuntu1804
    display_name: "${mongodb-version} ${topology} stress ${ruby}"
    tasks:
      - name: "test-mlaunch"

  - matrix_name: "stress"
    matrix_spec:
      stress: on
      ruby: <%= latest_ruby %>
      mongodb-version: <%= recent_mdb %>
      topology: replica-set
      os: ubuntu2204
    display_name: "${mongodb-version} ${topology} stress ${ruby}"
    tasks:
      - name: "test-mlaunch"

#  - matrix_name: "x509-tests"
#    matrix_spec:
#      auth-and-ssl: "x509"
#      ruby: <%= latest_ruby %>
#      mongodb-version: <%= latest_stable_mdb %>
#      topology: standalone
#      os: ubuntu2204
#    display_name: "${mongodb-version} ${topology} ${auth-and-ssl} ${ruby}"
#    tasks:
#      - name: "test-mlaunch"

  - matrix_name: "jruby-auth"
    matrix_spec:
      auth-and-ssl: [ "auth-and-ssl", "noauth-and-nossl" ]
      ruby: <%= jrubies.first %>
      mongodb-version: <%= latest_stable_mdb %>
      topology: <%= topologies %>
      os: ubuntu2204
    display_name: "${mongodb-version} ${topology} ${auth-and-ssl} ${ruby}"
    tasks:
      - name: "test-mlaunch"

 <% [
      [latest_ruby, latest_stable_mdb, 'ubuntu2204'],
      [supported_mri_ruby_2, '"6.0"', 'ubuntu2004']
    ].each do |rubies, mdb, distro|
 %>
  - matrix_name: <%= "zlib-#{rubies}" %>
    matrix_spec:
      auth-and-ssl: [ "auth-and-ssl", "noauth-and-nossl" ]
      ruby: <%= rubies %>
      mongodb-version: <%= mdb %>
      topology: "replica-set"
      compressor: 'zlib'
      os: <%= distro %>
    display_name: "${compressor} ${mongodb-version} ${topology} ${auth-and-ssl} ${ruby}"
    tasks:
      - name: "test-mlaunch"

  - matrix_name: <%= "snappy-#{rubies}" %>
    matrix_spec:
      auth-and-ssl: [ "auth-and-ssl", "noauth-and-nossl" ]
      ruby: <%= rubies %>
      mongodb-version: <%= mdb %>
      topology: "replica-set"
      compressor: 'snappy'
      os: <%= distro %>
    display_name: "${compressor} ${mongodb-version} ${topology} ${auth-and-ssl} ${ruby}"
    tasks:
      - name: "test-mlaunch"

  # the zstd-ruby gem does not support JRuby (explicitly). However, there is
  # apparently a zstd-jni gem for JRuby that we could investigate here; if
  # this test is ever supported to support jruby, the `sample_mri_rubies`
  # reference should be replaced with `sample_rubies`.
  - matrix_name: <%= "zstd-auth-#{rubies}" %>
    matrix_spec:
      auth-and-ssl: [ "auth-and-ssl", "noauth-and-nossl" ]
      ruby: <%= rubies %>
      mongodb-version: <%= mdb %>
      topology: "replica-set"
      compressor: 'zstd'
      os: <%= distro %>
    display_name: "${compressor} ${mongodb-version} ${topology} ${auth-and-ssl} ${ruby}"
    tasks:
      - name: "test-mlaunch"

  - matrix_name: <%= "activesupport-#{rubies}" %>
    matrix_spec:
      ruby: <%= rubies %>
      mongodb-version: <%= mdb %>
      topology: replica-set
      as: as
      os: <%= distro %>
    display_name: "AS ${mongodb-version} ${topology} ${ruby}"
    tasks:
      - name: "test-mlaunch"

  - matrix_name: <%= "bson-#{rubies}" %>
    matrix_spec:
      ruby: <%= rubies %>
      mongodb-version: <%= mdb %>
      topology: replica-set
      bson: "*"
      os: <%= distro %>
    display_name: "bson-${bson} ${mongodb-version} ${topology} ${ruby}"
    tasks:
      - name: "test-mlaunch"
  <% end %>

  - matrix_name: "fle above 4.4"
    matrix_spec:
      auth-and-ssl: "noauth-and-nossl"
      ruby: <%= supported_mri_rubies_3_ubuntu %>
      topology: [replica-set, sharded-cluster]
      mongodb-version: [ '6.0', '7.0', '8.0' ]
      os: ubuntu2204
      fle: helper
    display_name: "FLE: ${mongodb-version} ${topology} ${ruby}"
    tasks:
      - name: "test-fle"
  # kerberos integration tests are broken (RUBY-3266)
  # - matrix_name: "kerberos-integration"
  #   matrix_spec:
  #     ruby: <%= sample_rubies %>
  #     os: rhel8
  #   display_name: "Kerberos integration ${os} ${ruby}"
  #   tasks:
  #     - name: "test-kerberos-integration"

  - matrix_name: "kerberos-unit"
    matrix_spec:
      ruby: <%= latest_ruby %>
      mongodb-version: <%= latest_stable_mdb %>
      topology: standalone
      os: ubuntu2204
      auth-and-ssl: kerberos
    display_name: "Kerberos Tests"
    tasks:
      - name: "test-kerberos"

#  - matrix_name: "fle-latest"
#    matrix_spec:
#      auth-and-ssl: "noauth-and-nossl"
#      ruby: <%#= latest_ruby %>
#      topology: [replica-set, sharded-cluster]
#      mongodb-version: [ 'latest' ]
#      os: ubuntu2204
#      fle: helper
#    display_name: "FLE: ${mongodb-version} ${topology} ${ruby}"
#    tasks:
#      - name: "test-fle"

  - matrix_name: aws-auth-regular
    matrix_spec:
      # https://jira.mongodb.org/browse/RUBY-3311
      # auth-and-ssl: [ aws-regular, aws-assume-role, aws-ec2, aws-ecs, aws-web-identity ]
      # auth-and-ssl: [ aws-regular, aws-assume-role, aws-ecs, aws-web-identity ]
      # https://jira.mongodb.org/browse/RUBY-3659
      auth-and-ssl: [ aws-regular, aws-assume-role, aws-web-identity ]
      ruby: <%= latest_ruby %>
      topology: standalone
      mongodb-version: <%= latest_stable_mdb %>
      os: ubuntu2204
    display_name: "AWS ${auth-and-ssl} ${mongodb-version} ${ruby}"
    tasks:
      - name: "test-aws-auth"

  - matrix_name: ocsp-verifier
    matrix_spec:
      ocsp-verifier: true
      # No JRuby due to https://github.com/jruby/jruby-openssl/issues/210
      ruby: <%= supported_mri_rubies_3_ubuntu %>
      topology: standalone
      mongodb-version: <%= latest_stable_mdb %>
      os: ubuntu2204
    display_name: "OCSP verifier: ${mongodb-version} ${ruby}"
    tasks:
      - name: test-mlaunch

  - matrix_name: ocsp-must-staple
    matrix_spec:
      ocsp-algorithm: ecdsa
      ocsp-must-staple: on
      ocsp-delegate: on
      ruby: <%= latest_ruby %>
      topology: standalone
      mongodb-version: <%= latest_stable_mdb %>
      os: ubuntu2204
      auth-and-ssl: noauth-and-ssl
    display_name: "OCSP integration - must staple: ${mongodb-version} ${ruby}"
    tasks:
      - name: test-mlaunch

  - matrix_name: ocsp-unknown
    matrix_spec:
      ocsp-algorithm: rsa
      ocsp-status: unknown
      ruby: <%= latest_ruby %>
      topology: standalone
      mongodb-version: <%= latest_stable_mdb %>
      os: ubuntu2204
      auth-and-ssl: noauth-and-ssl
    display_name: "OCSP integration - unknown: ${mongodb-version} ${ruby}"
    tasks:
      - name: test-mlaunch

  <% [
    %w(valid none pass),
    %w(unknown none pass),
    %w(revoked none fail),

    %w(valid tlsInsecure=true pass),
    %w(unknown tlsInsecure=true pass),
    %w(revoked tlsInsecure=true pass),

    %w(valid tlsAllowInvalidCertificates=true pass),
    %w(unknown tlsAllowInvalidCertificates=true pass),
    %w(revoked tlsAllowInvalidCertificates=true pass),
  ].each do |status, extra_uri_options, outcome|
  %>
  - matrix_name: ocsp-connectivity
    matrix_spec:
      ocsp-algorithm: '*'
      ocsp-status: <%= status %>
      ocsp-delegate: '*'
      ocsp-connectivity: <%= outcome %>
      extra-uri-options: "<%= extra_uri_options %>"
      ruby: <%= latest_ruby %>
      topology: standalone
      mongodb-version: <%= latest_stable_mdb %>
      os: ubuntu2204
    display_name: "OCSP connectivity: ${ocsp-algorithm} ${ocsp-status} ${ocsp-delegate} ${extra-uri-options} ${mongodb-version} ${ruby}"
    tasks:
      - name: test-mlaunch
  <% end %>

  - matrix_name: ocsp-connectivity-jruby
    matrix_spec:
      # ECDSA does not work on JRuby.
      # https://github.com/jruby/jruby-openssl/issues/213
      ocsp-algorithm: rsa
      # We do not perform OCSP verification on JRuby, therefore the revoked
      # configuration fails (connection succeeds due to lack of verification
      # when it is expected to fail).
      # https://github.com/jruby/jruby-openssl/issues/210
      ocsp-status: [valid, unknown]
      ocsp-delegate: '*'
      ocsp-connectivity: pass
      ruby: <%= jrubies.first %>
      topology: standalone
      mongodb-version: <%= latest_stable_mdb %>
      os: ubuntu2204
    display_name: "OCSP connectivity: ${ocsp-algorithm} ${ocsp-status} ${ocsp-delegate} ${mongodb-version} ${ruby}"
    tasks:
      - name: test-mlaunch

  # https://jira.mongodb.org/browse/RUBY-3540
  #- matrix_name: testgcpkms-variant
  #  matrix_spec:
  #    ruby: <%= latest_ruby %>
  #    fle: helper
  #    topology: standalone
  #    os: ubuntu2204
  #    mongodb-version: <%= latest_stable_mdb %>
  #  display_name: "GCP KMS"
  #  tasks:
  #    - name: testgcpkms_task_group
  #      batchtime: 20160 # Use a batchtime of 14 days as suggested by the CSFLE test README

  # https://jira.mongodb.org/browse/RUBY-3672
  #- matrix_name: testazurekms-variant
  #  matrix_spec:
  #    ruby: ruby-3.0
  #    fle: helper
  #    topology: standalone
  #    os: debian11 # could eventually look at updating this to rhel80
  #    mongodb-version: 6.0
  #  display_name: "AZURE KMS"
  #  tasks:
  #    - name: testazurekms_task_group
  #      batchtime: 20160 # Use a batchtime of 14 days as suggested by the CSFLE test README

  - matrix_name: atlas-full
    matrix_spec:
      ruby: <%= latest_ruby %>
      os: ubuntu2204
    display_name: "Atlas (Full)"
    tasks:
      - name: testatlas_full_task_group

  - matrix_name: "atlas"
    matrix_spec:
      ruby: <%= supported_mri_rubies_3_ubuntu %>
      os: ubuntu2204
    display_name: "Atlas  connectivity tests ${ruby}"
    tasks:
       - name: test-atlas

# https://jira.mongodb.org/browse/RUBY-3311
#  - matrix_name: "aws-lambda"
#    matrix_spec:
#      ruby: 'ruby-3.2'
#      os: ubuntu2204
#    display_name: "AWS Lambda"
#    tasks:
#       - name: test_aws_lambda_task_group
